﻿//这个类主要用于心形图案绘制
//author 夏天的树人
//vesion 1.0
//绘制心形
//四种方向心形线
//r=a*(1+cos(angle))
//r=a*(1-cos(angle))
//r=a*(1+sin(angle))
//r=a*(1-sin(angle))


package org.summerTree.graphics
{
	import flash.display.Graphics;
	import flash.geom.Point;
	import flash.display.Sprite;

	public class HeartLine extends Base 
	{
		//private var LineColor:uint=0x000000;//默认是黑色
		public static const UP:String="up";
		public static const DOWN:String="down";
		public static const LEFT:String="left";
		public static const RIGHT:String="right";
		private var n:int=0;
		public function HeartLine()
		{
			init();
			
		}
		private function init():void
		{
			this.graphics.lineStyle(1,color);
			this.graphics.moveTo(0,0);
		}
		
		//绘制一颗心
		public function drawHeart(g:Graphics,radius:Number,direction:String="up"):void
		{
			var angle:Number=Math.PI/180;
			var r:Number;
			
			for(var i:int=0;i<=360;i++)
			{
			   switch (direction)
			   {
				case "up" :
					r=radius * (1 +Math.sin(angle*i));//上公式
					break;
				case "down" :
					r=radius * (1 - Math.sin(angle*i));//下公式
					break;
				case "left" :
					r=radius * (1 + Math.cos(angle*i));//左公式
					break;
				case "right" :
					r=radius * (1 - Math.cos(angle*i));//右公式
					break;
			    }
			   n=i;
			   var point:Point=Point.polar(r,angle*i);//极坐标转换笛卡尔坐标
			   drawLine(point);
			 }
		}
		private function drawLine(endPoint:Point):void
		{			 
			if (n==0)
			{
				this.graphics.moveTo(endPoint.x,endPoint.y);
				this.graphics.lineTo(endPoint.x,endPoint.y);
			}
			if (n>0)
			{
				this.graphics.lineTo(endPoint.x,endPoint.y);
			}
			 
		}
		////设置颜色
//		public function set color(value:uint):void
//		{
//			this.LineColor=value;
//		}
//		//获取颜色
//		public function get color():uint
//		{
//			return this.LineColor;
//		}
	}
}